<template>
	<el-main class="bg edit_wrap">
		<el-form ref="form" :model="form" status-icon label-width="120px" v-if="is_view()">
		<el-row class="row_ce">
							<el-col v-if="$check_field('get','club_name') || $check_field('add','club_name') || $check_field('set','club_name')" :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
				<el-form-item label="社团名称" prop="club_name">
												<el-input id="club_name" v-model="form['club_name']" placeholder="请输入社团名称"
							  v-if="(form['event_cancellation_id'] && $check_field('set','club_name')) || (!form['event_cancellation_id'] && $check_field('add','club_name'))" :disabled="disabledObj['club_name_isDisabled']"></el-input>
					<div v-else-if="$check_field('get','club_name')">{{form['club_name']}}</div>
											</el-form-item>
			</el-col>
								<el-col v-if="$check_field('get','event_name') || $check_field('add','event_name') || $check_field('set','event_name')" :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
				<el-form-item label="活动名称" prop="event_name">
												<el-input id="event_name" v-model="form['event_name']" placeholder="请输入活动名称"
							  v-if="(form['event_cancellation_id'] && $check_field('set','event_name')) || (!form['event_cancellation_id'] && $check_field('add','event_name'))" :disabled="disabledObj['event_name_isDisabled']"></el-input>
					<div v-else-if="$check_field('get','event_name')">{{form['event_name']}}</div>
											</el-form-item>
			</el-col>
								<el-col v-if="$check_field('get','event_date') || $check_field('add','event_date') || $check_field('set','event_date')" :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
				<el-form-item label="活动日期" prop="event_date">
								<el-date-picker :disabled="disabledObj['event_date_isDisabled']" v-if="(form['event_cancellation_id'] && $check_field('set','event_date')) || (!form['event_cancellation_id'] && $check_field('add','event_date'))" id="event_date"
						v-model="form['event_date']" type="date" placeholder="选择日期" value-format="yyyy-MM-dd">
					</el-date-picker>
					<div v-else-if="$check_field('get','event_date')">{{form['event_date']}}</div>
							</el-form-item>
			</el-col>
								<el-col v-if="$check_field('get','event_location') || $check_field('add','event_location') || $check_field('set','event_location')" :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
				<el-form-item label="活动地点" prop="event_location">
												<el-input id="event_location" v-model="form['event_location']" placeholder="请输入活动地点"
							  v-if="(form['event_cancellation_id'] && $check_field('set','event_location')) || (!form['event_cancellation_id'] && $check_field('add','event_location'))" :disabled="disabledObj['event_location_isDisabled']"></el-input>
					<div v-else-if="$check_field('get','event_location')">{{form['event_location']}}</div>
											</el-form-item>
			</el-col>
								<el-col v-if="$check_field('get','teacher_users') || $check_field('add','teacher_users') || $check_field('set','teacher_users')" :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
				<el-form-item label="教师用户" prop="teacher_users">
													<el-select v-if="(form['event_cancellation_id'] && $check_field('set','teacher_users')) || (!form['event_cancellation_id'] && $check_field('add','teacher_users'))" id="teacher_users" v-model="form['teacher_users']" :disabled="disabledObj['teacher_users_isDisabled']">
							<el-option v-for="o in list_user_teacher_users" :key="o['username']" :label="o['nickname'] + '-' + o['username']"
									   :value="o['user_id']">
							</el-option>
						</el-select>
						<el-select v-else-if="$check_field('get','teacher_users')" id="teacher_users" v-model="form['teacher_users']" :disabled="true">
							<el-option v-for="o in list_user_teacher_users" :key="o['username']" :label="o['nickname'] + '-' + o['username']"
									   :value="o['user_id']">
							</el-option>
						</el-select>
											</el-form-item>
			</el-col>
								<el-col v-if="$check_field('get','student_users') || $check_field('add','student_users') || $check_field('set','student_users')" :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
				<el-form-item label="学生用户" prop="student_users">
													<el-select v-if="(form['event_cancellation_id'] && $check_field('set','student_users')) || (!form['event_cancellation_id'] && $check_field('add','student_users'))" id="student_users" v-model="form['student_users']" :disabled="disabledObj['student_users_isDisabled']">
							<el-option v-for="o in list_user_student_users" :key="o['username']" :label="o['nickname'] + '-' + o['username']"
									   :value="o['user_id']">
							</el-option>
						</el-select>
						<el-select v-else-if="$check_field('get','student_users')" id="student_users" v-model="form['student_users']" :disabled="true">
							<el-option v-for="o in list_user_student_users" :key="o['username']" :label="o['nickname'] + '-' + o['username']"
									   :value="o['user_id']">
							</el-option>
						</el-select>
											</el-form-item>
			</el-col>
								<el-col v-if="$check_field('get','student_name') || $check_field('add','student_name') || $check_field('set','student_name')" :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
				<el-form-item label="学生姓名" prop="student_name">
												<el-input id="student_name" v-model="form['student_name']" placeholder="请输入学生姓名"
							  v-if="(form['event_cancellation_id'] && $check_field('set','student_name')) || (!form['event_cancellation_id'] && $check_field('add','student_name'))" :disabled="disabledObj['student_name_isDisabled']"></el-input>
					<div v-else-if="$check_field('get','student_name')">{{form['student_name']}}</div>
											</el-form-item>
			</el-col>
								<el-col v-if="$check_field('get','student_phone_number') || $check_field('add','student_phone_number') || $check_field('set','student_phone_number')" :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
				<el-form-item label="学生电话" prop="student_phone_number">
												<el-input id="student_phone_number" v-model="form['student_phone_number']" placeholder="请输入学生电话"
							  v-if="(form['event_cancellation_id'] && $check_field('set','student_phone_number')) || (!form['event_cancellation_id'] && $check_field('add','student_phone_number'))" :disabled="disabledObj['student_phone_number_isDisabled']"></el-input>
					<div v-else-if="$check_field('get','student_phone_number')">{{form['student_phone_number']}}</div>
											</el-form-item>
			</el-col>
								<el-col v-if="$check_field('get','student_id') || $check_field('add','student_id') || $check_field('set','student_id')" :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
				<el-form-item label="学生学号" prop="student_id">
												<el-input id="student_id" v-model="form['student_id']" placeholder="请输入学生学号"
							  v-if="(form['event_cancellation_id'] && $check_field('set','student_id')) || (!form['event_cancellation_id'] && $check_field('add','student_id'))" :disabled="disabledObj['student_id_isDisabled']"></el-input>
					<div v-else-if="$check_field('get','student_id')">{{form['student_id']}}</div>
											</el-form-item>
			</el-col>
								<el-col v-if="$check_field('get','reason_for_cancellation') || $check_field('add','reason_for_cancellation') || $check_field('set','reason_for_cancellation')" :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
				<el-form-item label="取消原因" prop="reason_for_cancellation">
								<el-input type="textarea" id="reason_for_cancellation" v-model="form['reason_for_cancellation']" placeholder="请输入取消原因"
						v-if="(form['event_cancellation_id'] && $check_field('set','reason_for_cancellation')) || (!form['event_cancellation_id'] && $check_field('add','reason_for_cancellation'))" :disabled="disabledObj['reason_for_cancellation_isDisabled']"></el-input>
					<div v-else-if="$check_field('get','reason_for_cancellation')">{{form['reason_for_cancellation']}}</div>
							</el-form-item>
			</el-col>
								<el-col v-if="$check_field('get','cancel_status') || $check_field('add','cancel_status') || $check_field('set','cancel_status')" :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
				<el-form-item label="取消状态" prop="cancel_status">
								<el-select id="cancel_status" v-model="form['cancel_status']"
						v-if="(form['event_cancellation_id'] && $check_field('set','cancel_status')) || (!form['event_cancellation_id'] && $check_field('add','cancel_status'))">
						<el-option v-for="o in list_cancel_status" :key="o" :label="o" :value="o">
						</el-option>
					</el-select>
					<div v-else-if="$check_field('get','cancel_status')">{{form['cancel_status']}}</div>
							</el-form-item>
			</el-col>
								<el-col v-if="$check_field('get','cancel_reply') || $check_field('add','cancel_reply') || $check_field('set','cancel_reply')" :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
				<el-form-item label="取消回复" prop="cancel_reply">
								<el-input type="textarea" id="cancel_reply" v-model="form['cancel_reply']" placeholder="请输入取消回复"
						v-if="(form['event_cancellation_id'] && $check_field('set','cancel_reply')) || (!form['event_cancellation_id'] && $check_field('add','cancel_reply'))" :disabled="disabledObj['cancel_reply_isDisabled']"></el-input>
					<div v-else-if="$check_field('get','cancel_reply')">{{form['cancel_reply']}}</div>
							</el-form-item>
			</el-col>
						
	
	
		
		
	
	
	
	
	</el-row>
			<el-col :xs="24" :sm="12" :lg="8" class="el_form_btn_warp">
				<el-form-item v-if="$check_action('/event_cancellation/view','set') || $check_action('/event_cancellation/view','add') || $check_option('/event_cancellation/table','examine')">
					<el-button type="primary" @click="submit()">提交</el-button>
					<el-button @click="cancel()">取消</el-button>
				</el-form-item>
				<el-form-item v-else>
					<el-button @click="cancel()">返回</el-button>
				</el-form-item>
			</el-col>

		</el-form>
	</el-main>
</template>

<script>
	import mixin from "@/mixins/page.js";

	export default {
		mixins: [mixin],
		data() {
			return {
				field: "event_cancellation_id",
				url_add: "~/api/event_cancellation/add?",
				url_set: "~/api/event_cancellation/set?",
				url_get_obj: "~/api/event_cancellation/get_obj?",
				url_upload: "~/api/event_cancellation/upload?",

				query: {
					"event_cancellation_id": 0,
				},

				form: {
								"club_name":  '', // 社团名称
										"event_name":  '', // 活动名称
										"event_date":  '', // 活动日期
										"event_location":  '', // 活动地点
										"teacher_users": 0, // 教师用户
										"student_users": 0, // 学生用户
										"student_name":  '', // 学生姓名
										"student_phone_number":  '', // 学生电话
										"student_id":  '', // 学生学号
										"reason_for_cancellation":  '', // 取消原因
										"cancel_status":  '', // 取消状态
										"cancel_reply":  '', // 取消回复
											"event_cancellation_id": 0, // ID
													},
				disabledObj:{
								"club_name_isDisabled": false,
										"event_name_isDisabled": false,
										"event_date_isDisabled": false,
										"event_location_isDisabled": false,
										"teacher_users_isDisabled": false,
										"student_users_isDisabled": false,
										"student_name_isDisabled": false,
										"student_phone_number_isDisabled": false,
										"student_id_isDisabled": false,
										"reason_for_cancellation_isDisabled": false,
										"cancel_status_isDisabled": false,
										"cancel_reply_isDisabled": false,
										},

	
				
				
				
				
					// 用户列表
				list_user_teacher_users: [],
						
					// 用户列表
				list_user_student_users: [],
						
				
				
				
										// 取消状态选项列表
				list_cancel_status: ['取消失败','取消成功'],
	
				
			
			}
		},
		methods: {

	
	
			
	
			
	
			
	
			
	
				/**
			 * 获取教师用户用户列表
			 */
			async get_list_user_teacher_users() {
                var json = await this.$get("~/api/user/get_list?user_group=教师用户");
                if(json.result && json.result.list){
                    this.list_user_teacher_users = json.result.list;
                }
                else if(json.error){
                    console.error(json.error);
                }
			},
					get_user_teacher_users(id){
				var obj = this.list_user_teacher_users.getObj({"user_id":id});
				var ret = "";
				if(obj){
					if(obj.nickname){
						ret = obj.nickname;}
					else{
						ret = obj.username;
					}
				}
				return ret;
			},
			
	
				/**
			 * 获取学生用户用户列表
			 */
			async get_list_user_student_users() {
                var json = await this.$get("~/api/user/get_list?user_group=学生用户");
                if(json.result && json.result.list){
                    this.list_user_student_users = json.result.list;
                }
                else if(json.error){
                    console.error(json.error);
                }
			},
					get_user_student_users(id){
				var obj = this.list_user_student_users.getObj({"user_id":id});
				var ret = "";
				if(obj){
					if(obj.nickname){
						ret = obj.nickname;}
					else{
						ret = obj.username;
					}
				}
				return ret;
			},
			
	
			
	
			
	
			
	
			
	
			
	
		
			/**
			 * 获取对象之前
			 * @param {Object} param
			 */
			get_obj_before(param) {
				var form = "";
																																			// 获取缓存数据附加
				form = $.db.get("form");
									$.push(this.form ,form);
												if(this.form && form){
					Object.keys(this.form).forEach(key => {
						Object.keys(form).forEach(dbKey => {
							// if(dbKey === "charging_standard"){
							// 	this.form['charging_rules'] = form[dbKey];
							// 	this.disabledObj['charging_rules_isDisabled'] = true;
							// };
							if(key === dbKey){
								this.disabledObj[key+'_isDisabled'] = true;
								this.form[key] = form[dbKey]
							}
							if(dbKey === "source_table"){
								this.form['source_table'] = form[dbKey];
							}
							if(dbKey === "source_id"){
								this.form['source_id'] = form[dbKey];
							}
							if(dbKey === "source_user_id"){
								this.form['source_user_id'] = form[dbKey];
							}
						})
					})
				}
						        if (this.form["event_date"] && this.form["event_date"].indexOf("-")===-1){
          this.form["event_date"] = this.$toTime(parseInt(this.form["event_date"]),"yyyy-MM-dd")
        }
																							$.db.del("form");
				return param;
			},

			/**
			 * 获取对象之后
			 * @param {Object} json
			 * @param {Object} func
			 */
			get_obj_after(json, func){

																if(json.result.obj["event_date"]=="0000-00-00"){
				  json.result.obj["event_date"] = null;
				}
				if(parseInt(json.result.obj["event_date"]) > 9999){
					json.result.obj["event_date"] = this.$toTime(parseInt(json.result.obj["event_date"]),"yyyy-MM-dd")
				}
																																																	

			},

																																																																																										async submit(param, func){
				if (!param) {
					param = this.form;
				}
								var pm = this.events("submit_before", Object.assign({}, param)) || param;
				var msg = await this.events("submit_check", pm);
				var ret;
				if (msg) {
					this.$toast(msg, 'danger');
				} else {
																																																																																												ret = this.events("submit_main", pm, func);
				}
				return ret;
			},
			/**
			 * 提交前验证事件
			 * @param {Object} 请求参数
			 * @return {String} 验证成功返回null, 失败返回错误提示
			 */
						submit_check(param) {
																																	if (!param.event_date){
					return "活动日期不能为空";
				}
																																																																																																																			return null;
			},

			is_view(){
				// var bl = this.user_group == "管理员";
				var bl = false;

				if(!bl){
					bl = this.$check_action('/event_cancellation/table','add');
					console.log(bl ? "你有表格添加权限视作有添加权限" : "你没有表格添加权限");
				}
				if(!bl){
					bl = this.$check_action('/event_cancellation/table','set');
					console.log(bl ? "你有表格添加权限视作有修改权限" : "你没有表格修改权限");
				}
				if(!bl){
					bl = this.$check_action('/event_cancellation/view','add');
					console.log(bl ? "你有视图添加权限视作有添加权限" : "你没有视图添加权限");
				}
				if(!bl){
					bl = this.$check_action('/event_cancellation/view','set');
					console.log(bl ? "你有视图修改权限视作有修改权限" : "你没有视图修改权限");
				}
				if(!bl){
					bl = this.$check_action('/event_cancellation/view','get');
					console.log(bl ? "你有视图查询权限视作有查询权限" : "你没有视图查询权限");
				}

				console.log(bl ? "具有当前页面的查看权，请注意这不代表你有字段的查看权" : "无权查看当前页，请注意即便有字段查询权限没有页面查询权限也不行");

				return bl;
			},
			/**
			 * 上传文件
			 * @param {Object} param
			 */
			uploadimg(param) {
				this.uploadFile(param.file, "avatar");
			},

		},
		created() {
													this.get_list_user_teacher_users();
								this.get_list_user_student_users();
																	},
	}
</script>

<style>
	.avatar-uploader .el-upload {
		border: 1px dashed #d9d9d9;
		border-radius: 6px;
		cursor: pointer;
		position: relative;
		overflow: hidden;
	}

	.avatar-uploader .el-upload:hover {
		border-color: #409EFF;
	}

	.avatar-uploader-icon {
		font-size: 28px;
		color: #8c939d;
		width: 178px;
		height: 178px;
		line-height: 178px;
		text-align: center;
	}

	.avatar {
		width: 178px;
		height: 178px;
		display: block;
	}
	
	.img_multiple{
		overflow: hidden;
	}
	.img_multiple .img_block{
		float: left;
		margin-right: 5px;
		margin-bottom: 5px;
		position: relative;
	}
	.img_multiple .img_block img{
		height: 100px;
		width: auto;
	}
	.img_multiple .img_del{
		position: absolute;
		top: 5px;
		right: 5px;
		width: 20px;
		height: 20px;
		background: #0000008a;
		color: #fff;
		line-height: 20px;
		text-align: center;
		border-radius: 100%;
		cursor: pointer;
	}




</style>
